from ctypes import *
libad=cdll.LoadLibrary("/home/pi/Documents/rmo.so")
def p_count(Dif,apnum):
    sort_Dif=sorted(Dif)
    Re=sort_Dif[::-1]
    ave_trouths=sum(sort_Dif[10:apnum+10])/(apnum)
    ave_peaks=sum(Re[10:apnum+10])/(apnum)
    A01=(ave_peaks)/3.5
    A02=(ave_trouths)/3.5
    N_Dif=[]
    for x in Dif:
        if A02<x<A01:
            x=0
            N_Dif.append(x)
        else:
            N_Dif.append(x)
    peaks = 0
    troughs = 0
    troughs=libad.rm(troughs)
    for idx in range(1, len(N_Dif)-1):
        if N_Dif[idx-1] > N_Dif[idx] < N_Dif[idx+1]:
            troughs=troughs+1
        if N_Dif[idx-1] < N_Dif[idx] > N_Dif[idx+1]:
            peaks=peaks+1
    Bi_Dif=[]
    for x in N_Dif:
        if x>0:
            x=1
            Bi_Dif.append(x)
        elif x<0:
            x=-1
            Bi_Dif.append(x)
    diff_Bi=[]
    for idx in range(1, len(Bi_Dif)):
        biTem=Bi_Dif[idx]-Bi_Dif[idx-1]
        diff_Bi.append(biTem)
    P_Peak=diff_Bi.count(2)+1
    P_Trough=diff_Bi.count(-2)+1
    P_Pount_N=[peaks,troughs,P_Peak,P_Trough]
    return P_Pount_N
